<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>RxJS swtichMap</title>
</head>
<body>
  <button>click me</button>
</body>
<script src="https://unpkg.com/@reactivex/rxjs@5.0.0-beta.12/dist/global/Rx.js"></script>
<script>
  const button = document.querySelector('button');

  const obs1 = Rx.Observable.fromEvent(button, 'click');
  const obs2 = Rx.Observable.interval(1000);

  // trigger some value emissions whenever another Observable emits a value
  // when button clicks, obs2 will be subscribed
  obs1.switchMap(event => obs2)
    .subscribe(val => console.log(val));
</script>
</html>
